package com.webwork.mood.record.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.webwork.mood.record.dao.AwardDao;
import com.webwork.mood.record.dataobject.AwardInfo;
import com.webwork.mood.record.service.AwardService;
import com.webwork.mood.util.Paging;
import com.webwork.mood.util.StrManager;

@Service
public class AwardServiceImpl implements AwardService {

	@Autowired
	private AwardDao awardDao;
	
	@Override
	public void insert(AwardInfo award) {
		awardDao.insert(award);
	}
	
	@Override
	public List<AwardInfo> query(AwardInfo award) {
		return this.query(award, new Paging(0, 0));
	}
	
	@Override
	public List<AwardInfo> query(AwardInfo award, Paging page) {
		return awardDao.query(award, page.getCurrPage(), page.getPageSize());
	}
	
	@Override
	public AwardInfo get(String awardName) {
		if (StrManager.isEmpty(awardName)) {
			return null;
		}
		AwardInfo queryObj = new AwardInfo();
		queryObj.setAwardName(awardName);
		List<AwardInfo> awards = this.query(queryObj);
		if (awards != null && awards.size() > 0) {
			if (awards.size() > 1) {
				System.out.println("存在不止一条记录!");
			} else {
				return awards.get(0);
			}
		} else {
			System.out.println("找不到该记录!");
		}
		return null;
	}

	@Override
	public int count(AwardInfo record) {
		return awardDao.count(record);
	}

}
